package com.atguigu;

import com.atguigu.config.MainConfigOfLifeCycle;
import com.atguigu.config.MainConfigOfProfile;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.sql.DataSource;

/**
 * @author Honglixi
 * @create 2021-03-27 14:18
 */
public class IOCTest_Profile {
    //1.使用命令行动态参数
    //2.
    @Test
    public void test(){

        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        //1.创建一个applicationContext

        //2.设置需要激活的环境
        applicationContext.getEnvironment().setActiveProfiles("test","dev");
        //注册主配置类
        applicationContext.register(MainConfigOfProfile.class);
        //4.启动刷新容器
        applicationContext.refresh();

        String[] namesForType = applicationContext.getBeanNamesForType(DataSource.class);
        for (String s : namesForType) {
            System.out.println(s);
        }
        applicationContext.close();
    }
}
